import { RenderableBehaviour, getGameObjectById, Transform, SerilizeField, propertyEditor_Number, propertyEditor_None, propertyEditor_String } from "../gameengine";
import { ColliderSystem } from "./colliderSystem";
import { ItemBehaviour } from "../item/item";

export enum RectColliderType {

    MAINROLE = 0,
    WALL = 1,
    ITEM = 2
}


export class Rect_Collider extends RenderableBehaviour {

    @SerilizeField(propertyEditor_Number)
    public type: number = 0;

    @SerilizeField(propertyEditor_Number)
    public width: number = 0;

    @SerilizeField(propertyEditor_Number)
    public height: number = 0;

    @SerilizeField(propertyEditor_Number)
    public x: number = 0;   //碰撞盒x坐标（基于原本图标的xy）

    @SerilizeField(propertyEditor_Number)
    public y: number = 0;   //碰撞盒y坐标

    public id: string;

    public canTalk: boolean = false;

    @SerilizeField(propertyEditor_String)
    public clue: string;

    public canPick: boolean = false;
    public key: string;

    @SerilizeField(propertyEditor_None)
    public isDoor: boolean = false;
    @SerilizeField(propertyEditor_None)
    public isLocked: boolean = false;
    @SerilizeField(propertyEditor_Number)
    public doorSceneID: number = -1;

    public isHiddenClue: boolean = false;

    public isDisappear:boolean = false;

    public onColliderStart: Function;


    protected onStart() {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        this.id = this.displayObject.id;
        // console.log(this.id);

        colliderSystem.addRectCollider(this);
        // this.displayObject.renderNode = this;
    }

    onEnd() {
        const colliderSystem = getGameObjectById("Scene").getScript(ColliderSystem);
        colliderSystem.removeRectCollider(this);
        // console.log("删除碰撞体")
    }

    protected onUpdate(advancedTime: number) {
    }

    public get left() {
        const transform = this.displayObject.getScript(Transform);
        return transform.x + this.x;
    }

    public get top() {
        const transform = this.displayObject.getScript(Transform);
        return transform.y + this.y;

    }

    public get right() {
        return this.left + this.width;
    }

    public get bottom() {
        return this.top + this.height;
    }

    onRender(context: CanvasRenderingContext2D) {
        // context.save();
        // context.strokeRect(0, 0, this.width, this.height);
        // context.restore();
    }


}